package com.lhdx.practical.dao;

import com.lhdx.practical.bean.Fraction;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface FractionDao extends CrudRepository<Fraction,Long> {
    List<Fraction> findAllByAuthoridAndGroupidAndSid(long authorid,long groupid,long sid);

    List<Fraction> findAllByPersonidAndGroupidAndMid(long personid,long groupid,long mid);

    Fraction findByPersonidAndSidAndAuthorid(long personid,long sid,long authorid);

    /**
     * 老师修改分数
     * @param id
     * @param teacherscore
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update fraction set teacherscore = ?2 where personid = ?1 and sid = ?3",nativeQuery = true)
    void updateTeacherScore(long id,double teacherscore,long sid);
}
